<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<link href=" themes/css/ui.common.css" rel="stylesheet" type="text/css" />
<link href=" themes/css/ui.child.css" rel="stylesheet" type="text/css" />
<link href=" themes/css/ui.tips.css" rel="stylesheet" type="text/css" />
<script src=" Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src=" Scripts/jquery-ui-1.8.custom.min.js"
	type="text/javascript"></script>
<script src=" Scripts/ui.admincp.js" type="text/javascript"
	charset="UTF-8"></script>
<script src=" Scripts/ui.tips.js" type="text/javascript"></script>
<script src=" Scripts/ui.default.js " type="text/javascript"
	charset="UTF-8"></script>
<link id="skin_css" rel="stylesheet" type="text/css"
	href=" themes/css/ui.c.blue.css"></link>
<STYLE type="text/css">
.editorArea {
	display: none;
}
</STYLE>
<script type="text/javascript" src="Scripts/ui.dialogFormHelper.js"></script>
<script type="text/javascript">
		//鼠标点击的时候,出现编辑框,回车可以提交请求
		$(function(){
			registeRowFuncButton();
			$(".textPanel").click(function(){
			     var __id = $(this).attr("oid");
			     $("#sender_"+__id).click();
			     $("#editor_"+__id).focus();
			  });
		   $(".textBox").keydown(function(e){ 
		      
          		if(e.keyCode==13){ 
           			$("#sender_"+$(this).attr("oid")).click();//处理事件 
       			} 
          });  
		
		});
	function showEditor(id)
	{
	   var content = $("#content_"+id);
	   var editorArea = $("#editorArea_"+id);
	   var editor = $("#editor_"+id);
	   editor.val(content.text());
	   
	   editorArea.show();  
		
	   $("#switcher_"+id).attr("src"," themes/icons/ok.png").attr("title","提交");
	   content.hide(); 
	}
	
	function hideEdit(id,withSubmit)
	{
	   var content = $("#content_"+id);
	   var editorArea = $("#editorArea_"+id);
	   var editor = $("#editor_"+id);
	   editorArea.hide();   
	 	var text = editor.val();
	   //...
	   //显示原内容。。 
       //withSubmit
       //submit to Db
       if(withSubmit==true){
         if(content.text()!= text)
         { 
            //...
            //post to server...
                $.post("sectionCategory!modify.action", 
               		{"categoryId":id,"categoryName":text},
                		 function (data) {  
                        }, 
              		     "json"); 
         }
        //
        content.text(text);
       } 
       $("#switcher_"+id).attr("src"," themes/icons/edit.png").attr("title","进行编辑");
        content.show();
	}
	
	function switchSave(id,withSubmit)
	{  
	 var ___id= "#sender_"+id ;
	  var sender= $(___id); 
	   var stateCode = sender.attr("state"); 
	   if(stateCode==0 || stateCode==undefined)
	   { 
	     // 进行保存 。 
	     $(sender).attr("state",1);  
	     showEditor(id); 
	
	   }
	   if(stateCode==1)
	   { 
	     $(sender).attr("state",0);
	     $("#submitting").show();
	     hideEdit(id,withSubmit);  
	   }
	}

     function cancelSave(id,withSubmit)
     {
         switchSave(id,false);
          
     }
     
    function toDeleteHandler(e)
	{
		var categoryId = e.entityId;
		location="sectionCategory!delete.action?categoryIds="+categoryId;
	}
	
    function checkAll(str)
	{
		var items = document.getElementsByName(str);		//获取所有复选框
		var totalNum = items.length;	//获取复选框的个数
 		for (var i=0; i<totalNum; i++)
		items[i].checked = window.event.srcElement.checked;//通过单击的按钮判断是选中还是未选
	}
	
	function deleteAll(str)
	{
		var isTo = checkDeleteAll("部门信息记录");

		if(isTo==false)
		return ;
      	var items = document.getElementsByName(str);	 //获取所有复选框
		var totalNum = items.length;  //获取复选框的个数
		var delStr = "";
 			for (var i=0; i<totalNum; i++){
				if(items[i].checked == true){
				delStr += items[i].value + ","; 
			}
		}
		delStr = delStr.substring(0, delStr.length -1);
		location.href="sectionCategory!delete.action?categoryIds="+delStr;
	}
	
	</script>
</head>

<body>
	<div class="PageChild_Title">
		<img src=" themes/images/default/icons/archives.png"
			class="PageChild_Tbtnpic" /> <span class="PageChild_separate"></span>
		<span class="PageChild_TbtnText"><h2>部门类型</h2></span> <span
			class="PageChild_separate"></span>
		<div id="marker" class="red-tips"></div>
		<div class="clear"></div>
	</div>
	<div class="PageChild_Where">
		<table style="height: 60px;" border="0" cellpadding="0"
			cellspacing="0">
			<tr>
				<td style="width: 110px;" class="mtd" valign="bottom"><br>类型名称:
				</td>
				<td style="width: 1000px;" valign="top"><input name="txt_Tile"
					type="text" maxlength="100" id="add" style="width: 200px;" />
					&nbsp; <input type="button" value="添 加" class="o-btn SubmitButton"
					onclick='var text= $("#add").val();if($.trim(text).length==0){alert("请输入名称.");$("#add").focus(); return false;} location="sectionCategory!add.action?categoryName="+text' />
				</td>
			</tr>

			<tr>
				<td colspan="2">
						<s:if test="count!=null">
						<span id="lbl_list_count">共搜索到 <b>${count}</b> 条符合条件的记录。
						</span></s:if>
				</td>
			</tr>
		</table>
	</div>
	<div class="PageChild_List">
		<table width="100%" border="0" cellspacing="0"
			style="text-align: left">
			<tbody class="PageChild_List_head">
				<tr>
					<td width="16"><input id="Chk_All" type="checkbox"
						name="Chk_All" onclick="checkAll('ReptShow$ctl01$Chk_Num')" /></td>
					<td width="16"><img
						src=" themes/images/default/icons/pcde_314.png" width="16"
						height="16" /></td>
					<td>名称</td>
					<td class="td_width40">编辑</td>
					<td class="td_width40">删除</td>
					<td class="td_width40">状态</td>
				</tr>
			</tbody>
			<tbody class="PageChild_List_main" style="text-align: left">
				<s:if test="list != null && list.size != 0">
					<s:iterator value="list" var="item" status="no">
						<tr class='td_no_bord'>
							<td class="td_width25"><span title="24"><input
									id="Chk_Num" type="checkbox" name="ReptShow$ctl01$Chk_Num"
									value="${item.categoryId}" /></span></td>
							<td class="td_width25"><s:property value="#no.count" /></td>
							<td title="单击内容进行编辑.回车提交更新."><span oid="${item.categoryId}"
								class="textPanel" id="content_${item.categoryId}">
									${item.categoryName} </span>
								<div id="editorArea_${item.categoryId}" class="editorArea">
									<input id="editor_${item.categoryId}" class="textBox"
										type="text" size="50" maxlength="40" oid="${item.categoryId}" />
								</div></td>
							<td><a class="editButton" id="sender_${item.categoryId}"
								href="javascript:void(0);" state="0"
								onclick="switchSave(${item.categoryId},true);"> <img
									id="switcher_${item.categoryId}" src=" themes/icons/edit.png"
									title="进行编辑" />
							</a> &nbsp;</td>
							<td><a href="javascript:;" class="ui-link-delete-button"
								entityId="${item.categoryId}" onclick=''><img
									src="themes/icons/delete.png" /> </a></td>
							<td><s:if test="#item.states==0">
									<a href="javascript:;"
										onclick='location="sectionCategory!toEnable.action?categoryId=${item.categoryId}"'><img
										src=" themes/icons/btn_disable.png" /> </a>
								</s:if> <s:if test="#item.states==1">
									<a href="javascript:;"
										onclick='location="sectionCategory!toDisable.action?categoryId=${item.categoryId}"'><img
										src=" themes/icons/btn_enable.png" /> </a>
								</s:if></td>
						</tr>
					</s:iterator>
				</s:if>
				<s:else>
					<tr>
						<td colspan="6">无记录</td>
					</tr>
				</s:else>
			</tbody>
		</table>
	</div>
	<div>
		<input type="button" name="btn_Delete" class="o-btn SubmitButton"
			value="删 除" id="btn_Delete"
			onclick="deleteAll('ReptShow$ctl01$Chk_Num')" />
	</div>
</body>
</html>